import parole
from parole.colornames import colors
from parole.display import interpolateRGB
import pygame, random

import sim, main, sim_items
from util import *

class Flare(sim_items.LightSource):
    def __init__(self):
        
        sim_items.LightSource.__init__(self,
                'short flare',     #name
                50,     # layer
                parole.map.AsciiTile('*', colors['Red']),
                1,  # weight
                1000,   # light energy
                (255,0,0),  # light color
                15,    # light intensity
                2*60000,  # burn time
                unidDescription="A small red tube with a cord protruding from "\
                    "one side. When the cord is pulled, an internal chemical "\
                    "reaction occurs producing a brief but intense red light "\
                    "that cannot be extinguished.",
                dousable=False)

        self.snuffable = False
        self.startIntensity = self.lightIntensity
        self.startBurnTime = self.burnTime

    def listen(self, event):
        super(Flare, self).listen(event)

        # Flare's brightness decreases over time until it's dead
        # FIXME: doesn't work when waiting. crashes in combat?
        if event.id == 'burn' and event.args[0] is self:
            if not self.burnTime:
                return # we're already extinguished
            newIntensity = (float(self.burnTime) / self.startBurnTime) * \
                            self.startIntensity
            main.schedule.add(sim.Event('update light', main.schedule.time,
                (self, self.lightRGB, newIntensity), dests=[self]))



#========================================
thingClass = Flare


